<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
class HousingResource extends Model
{
    protected $table='housingresources';
    protected $guarded=[];
    public $timestamps=false;

    //保存房源

    public static function newHousing($request){
        $data['householder']=$request->householder;
        $data['block_name']=$request->block_name;
        $data['housing_name']=$request->housing_name;
        $data['housing_number']=$request->housing_number;
        $data['room_number']=$request->room_number;
        $data['floor_number']=$request->floor_number;
        $data['area']=$request->area;
        $data['house_deliver_time']=$request->house_deliver_time;
        $data['created_time']=Carbon::now();
        $newProject=HousingResource::create($data);
        if($newProject){
            return redirect()->back()->with('status','小主！新建成功！');
        }else{
            return redirect()->back()->with('status','小主！新建失败!');
        }
    }


    /*
     * 修改房源
     * */
    public static function updateHousing($request){
        $data['householder']=$request->householder;
        $data['block_name']=$request->block_name;
        $data['housing_name']=$request->housing_name;
        $data['housing_number']=$request->housing_number;
        $data['room_number']=$request->room_number;
        $data['floor_number']=$request->floor_number;
        $data['area']=$request->area;
        $data['house_deliver_time']=$request->house_deliver_time;
        $updateProject=HousingResource::where('id',$request->housing_id)->update($data);
        if($updateProject){
            return  back()->with('status','修改成功');
        }else{
            return  back()->with('status','房源信息未做任何修改');
        }
    }
}
